#ifndef STRVEC_H
#define STRVEC_H

#include <string>
#include <memory>
#include <utility>


class StrVec
{
public:
    StrVec() :
        elements(nullptr), first_free(nullptr), cap(nullptr) { }
    StrVec(std::initializer_list<std::string>);
    StrVec(const StrVec&);
    StrVec& operator = (const StrVec&);
    ~StrVec();

    void push_back(const string &);
    size_t size() const { return first_free - elements; }
    size_t capacity() const { return cap - elements; }
    std::string* begin() const { return elements; }
    std::string* end() const { return first_free; }
    void reserve(size_t n) { if (n > capacity()) reallocate(n);}
    void resize(size_t);
    void resize(size_t, const std::string&);

private:
    std::string *elements;
    std::string *first_free;
    std::string *cap;

    static std::allocator<std::string> alloc;
    void chk_n_alloc();
    std::pair<std::string*, std::string*> alloc_n_copy(const string&,
                                                       const string&);
    void free();
    void reallocate();
    void reallocate(size_t);
};

#endif // STRVEC_H
